package com.igoal.dto;

import com.igoal.entity.User;
import com.igoal.entity.UserInfo;
import com.igoal.utils.StringUtils;
import com.igoal.utils.SynchronizeAttributeWithOther;
import com.igoal.utils.SynchronizeDirection;

public class UserActivityLogDTO extends UserActivityDTO {
	private String componentOwnerName;
	private String componentOwnerDisplayName;
	private String componentTitle;

	public String getComponentTitle() {
		return componentTitle;
	}

	public void setComponentTitle(String componentTitle) {
		this.componentTitle = componentTitle;
	}

	public String getComponentOwnerName() {
		return componentOwnerName;
	}

	public void setComponentOwnerName(String componentOwnerName) {
		this.componentOwnerName = componentOwnerName;
	}

	public String getComponentOwnerDisplayName() {
		return componentOwnerDisplayName;
	}

	public void setComponentOwnerDisplayName(String componentOwnerDisplayName) {
		this.componentOwnerDisplayName = componentOwnerDisplayName;
	}

	@SynchronizeAttributeWithOther(direction = SynchronizeDirection.FROM, value = "componentOwner")
	public void initComponentOwnerName(Object entity) {
		if (entity != null && entity instanceof User) {
			User user = (User) entity;
			componentOwnerName = user.getUsername();

			UserInfo info = user.getUserInfo();
			String firstName = info.getFirstName();
			String midleName = info.getMiddleName();
			String lastName = info.getLastName();

			componentOwnerDisplayName = "";
			if (StringUtils.isNotBlank(lastName)) {
				componentOwnerDisplayName += lastName + " ";
			}
			if (StringUtils.isNotBlank(midleName)) {
				componentOwnerDisplayName += midleName + " ";
			}
			if (StringUtils.isNotBlank(firstName)) {
				componentOwnerDisplayName += firstName;
			}
			componentOwnerDisplayName = StringUtils
					.stripToNull(componentOwnerDisplayName);
			if (componentOwnerDisplayName == null) {
				componentOwnerDisplayName = componentOwnerName;
			}
		}
	}
}
